<template>
	<view class="" v-if="isbool(order)">
		<!-- {{item}} -->
		<view class="fwb fs12 c11 flrc padtb2 bdbda">
			<view class="flex1" v-if="isbool(order.planSn)">计划点检[{{order.planSn}}]</view>
			<view class="flex1" v-else>随机点检</view>
			<view>#{{order.id}}</view>
		</view>
		
		<view class="flrc bdbda  fs24 padtb3">
			<view class="flex1 flcc">
				<view class="fwb">{{order.numPoints}}</view>
				<view class="fs8">点检项目</view>
			</view>
			<view class="flex1 flcc">
				<view class="fwb">{{order.numNotCheck}}</view>
				<view class="fs8">未检项目</view>
			</view>
			<view class="flex1 flcc">
				<view class="fwb">{{order.numError}}</view>
				<view class="fs8">异常项目</view>
			</view>
		</view>
		<view class="flrc bdbda">
			<view>点检职工:</view>
			<view class="flex1 tar padtb2">{{isnull(order.createBy)?'未设置':order.createBy.name}}</view>
		</view>
		<view class="flrc bdbda">
			<view>开始时间:</view>
			<view class="flex1 tar padtb2">{{datetime(order.startAt)}}</view>
		</view>
		<view class="flrc bdbda">
			<view>完成时间:</view>
			<view class="flex1 tar padtb2">{{datetime(order.endAt)}}</view>
		</view>
		<view class="flrc bdbda">
			<view>点检状态:</view>
			<view class="flex1 tar padtb2 flex-r flex-end">
				<status classes="pad1 round3" :item="order.status"></status>
			</view>
		</view>
		<view class="pad10" v-if="!isbool(order)">
			<view class="pad10 bdda tac c12">无效的数据</view>
		</view>
		<view class="pos-a l0 r0 t0 b0 flcc bcaf4 c12" v-show="loading && !isbool(order)">
			<text class="fa fa-spinner fa-spin fa-4x"></text>
		</view>
		
	</view>
</template>

<script>
	export default {
		props: {
			value: '',
			item: '',
			itemId: '',
			iri: '',
			code: ''
		},
		data() {
			return {
				order: '',
				ready: false,
				loading: false,
			}
		},
		methods: {
			getById(val) {
				this.loading = true
				this.$api.get("/api/machineorderChecks/" + val, {}, res => {
					this.loading = false
					this.log(res)
					this.order = res.d
				})
			},
			getByCode(code) {
				this.loading = true
				this.$api.get("/api/machineorderChecks", {
					_where: {
						eq: {
							code
						}
					}
				}, res => {
					this.loading = false
					this.log(res)
					if (res.d.length == 1) {
						this.order = res.d[0]
					} else {
						if (res.d.length == 0) {
							this.$com.showToast('未找到设备')
						} else {
							this.$com.showToast('检测到重复的编号，请管理后台核对')
						}
					}
				})
			},
			update() {
				if (this.isbool(this.item)) {
					this.order = this.item
					return
				}
				if (this.isbool(this.id)) {
					this.getById(this.id)
					return
				}
				if (this.isbool(this.iri)) {
					this.getById(this.iri.split("/").pop())
					return
				}
				if (this.isbool(this.code)) {
					this.getByCode(this.code)
					return
				}
			}
		},
		created() {
			this.log("created")
			this.log(this.item)
		},
		mounted() {
			this.log("mounted")
			this.log(this.item)
			// #ifdef MP-WEIXIN || APP-PLUS
			if(this.isbool(this.value)) this.getById((this.value + '').split("/").pop())
			// #endif
			this.update()
		},
		watch: {
			id(val) {
				if (!this.$com.isbool(val)) return
				this.getById(val)
			},
			code(val) {
				if (!this.$com.isbool(val)) return
				this.getByCode(val)
			},
			value(val) {
				if (!this.$com.isbool(val)) return
				this.getById(val.split("/").pop())
			},
			order(order) {
				if (!this.$com.isbool(order)) return
				this.$emit('input', '/api_/machine_order_checks/' + order.id)
			},
			item(){
				this.update()
			}
		}
	}
</script>

<style>

</style>
